/*河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
*/
package cn.javaxc.system.action.systemadmin;
import java.io.*;
import java.util.*;
import java.sql.*;
import cn.javaxc.model.base.SQL;
import cn.javaxc.model.base.SQLList;
import cn.javaxc.model.base.SQLMap;
import cn.javaxc.model.base.SQLParam;
import cn.javaxc.model.page.BatisPage;
import cn.javaxc.mvcwork.controller.web.TreeBean;
import cn.javaxc.mvcwork.util.common.CommonUtil;
import cn.javaxc.mvcwork.util.common.MapListUtil;
import cn.javaxc.mvcwork.util.helper.FrameHelper;
import cn.javaxc.mvcwork.util.helper.TreeTableHelper;
import org.springframework.beans.factory.annotation.Autowired;
import cn.javaxc.system.action.base.BaseAction;
import cn.javaxc.system.mapper.systemadmin.WorkflowDetailsMapper;
public class WorkflowDetails extends BaseAction
{
    @Autowired(required=false)
	private WorkflowDetailsMapper mapper;
    /**
    工作流明细
    */
    
    public Map workflowDetails() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> steps=mapper.steps(params);
        result.put("steps", steps);
        
        return result;
    }
    /**
    修改流程
    */
    
    public Map modificationProcess() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> UserList=mapper.UserList(params);
        result.put("UserList", UserList);
        
        
        SQLList<SQLMap> l_role=mapper.l_role(params);
        result.put("l_role", l_role);
        
        
        SQLList<SQLMap> steps=mapper.steps(params);
        result.put("steps", steps);
        
        return result;
    }
    /**
    选择岗位
    */
    
    public Map postSelection() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        TreeBean tb;
        
        tb = createTreeBean("s_firm_treecols");
        SQLList<SQLMap> s_firm=mapper.s_firm(params);
        s_firm = s_firm.buildTree(tb,tb.getPid());
        result.put("s_firm", s_firm);
        
        
        SQLList<SQLMap> s_role=mapper.s_role(params,pagination);
        s_role.setPagedListInfo(pagination);
        result.put("s_role", s_role);
        
        return result;
    }
    /**
    选择岗位人员
    */
    
    public Map postSelectionPerson() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> s_info=mapper.s_info(params,pagination);
        s_info.setPagedListInfo(pagination);
        result.put("s_info", s_info);
        
        return result;
    }
    /**
    修改时间
    */
    
    public Map modificationTime() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> UserList=mapper.UserList(params);
        result.put("UserList", UserList);
        
        
        SQLList<SQLMap> steps=mapper.steps(params);
        result.put("steps", steps);
        
        
        SQLList<SQLMap> s_plan=mapper.s_plan(params);
        SQLMap s_plan_emt=s_plan.getExistfirst();
        result.put("s_plan", s_plan_emt);
        
        return result;
    }
    /**
    */
    
    public Map d_step() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.d_step(params);
        
        return result;
    }
    /**
    修改流程修改
    */
    
    public Map modificationProcessSubmit() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        for (SQLMap emt:hqlBean.getTableElements("action_step")){
            params=new SQLParam(request,emt.getMap());
            mapper.modificationProcessSubmit(params);
        }
        
        return result;
    }
    /**
    */
    
    public Map u_step() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.u_step(params);
        
        
        SQLList<SQLMap> t_user=mapper.t_user(params);
        SQLMap t_user_emt=t_user.getExistfirst();
        result.put("t_user", t_user_emt);
        
        
        SQLList<SQLMap> t_plan=mapper.t_plan(params);
        SQLMap t_plan_emt=t_plan.getExistfirst();
        result.put("t_plan", t_plan_emt);
        
        
        SQLList<SQLMap> s_steps=mapper.s_steps(params);
        result.put("s_steps", s_steps);
        
        
        SQLList<SQLMap> skips=mapper.skips(params);
        result.put("skips", skips);
        
        
        
        
        
        
        for (SQLMap emt:FrameHelper.createStepWorkTime(s_steps,skips,"step_id","dura_inttime")){
            params=new SQLParam(request,emt.getMap());
            params.put("_start_time",getAfterWorkHour(getParameter("start_time")
            ,emt.getInt("start_inttime")*1.0/3600
            ,t_user.getExistfirst().getString("station_type")
            ,t_user.getExistfirst().getString("org_id")
            ));
            params.put("_end_time",getAfterWorkHour(
            getParameter("start_time")
            ,emt.getInt("end_inttime")*1.0/3600
            ,t_user.getExistfirst().getString("station_type")
            ,t_user.getExistfirst().getString("org_id")
            ));
            mapper.b_action_step(params);
        }
        
        return result;
    }
    /**
    */
    
    public Map u_step_work() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> t_user=mapper.t_user(params);
        SQLMap t_user_emt=t_user.getExistfirst();
        result.put("t_user", t_user_emt);
        
        
        SQLList<SQLMap> s_steps=mapper.s_steps(params);
        result.put("s_steps", s_steps);
        
        
        SQLList<SQLMap> skips=mapper.skips(params);
        result.put("skips", skips);
        
        
        Object start_time =
        mapper.start_time(params);
        result.put("start_time", start_time);
        
        
        for (SQLMap emt:FrameHelper.createStepWorkTime(s_steps,skips,"item_work_id","dura_inttime")){
            params=new SQLParam(request,emt.getMap());
            params.put("_start_time",getAfterWorkHour(
            start_time
            ,emt.getInt("start_inttime")*1.0/3600
            ,t_user.getExistfirst().getString("station_type")
            ,t_user.getExistfirst().getString("org_id")
            ));
            params.put("_end_time",getAfterWorkHour(
            start_time
            ,emt.getInt("end_inttime")*1.0/3600
            ,t_user.getExistfirst().getString("station_type")
            ,t_user.getExistfirst().getString("org_id")
            ));
            mapper.u_step_work(params);
        }
        
        
        
        return result;
    }
    /**
    */
    
    public Map u_work() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> t_user=mapper.t_user(params);
        SQLMap t_user_emt=t_user.getExistfirst();
        result.put("t_user", t_user_emt);
        
        
        SQLList<SQLMap> s_steps=mapper.s_steps(params);
        result.put("s_steps", s_steps);
        
        
        SQLList<SQLMap> skips=mapper.skips(params);
        result.put("skips", skips);
        
        
        Object start_time =
        mapper.start_time(params);
        result.put("start_time", start_time);
        
        
        for (SQLMap emt:FrameHelper.createStepWorkTime(s_steps,skips,"step_id","dura_inttime")){
            params=new SQLParam(request,emt.getMap());
            params.put("_start_time",getAfterWorkHour(start_time
            ,emt.getInt("start_inttime")*1.0/3600
            ,t_user.getExistfirst().getString("station_type")
            ,t_user.getExistfirst().getString("org_id")
            ));
            params.put("_end_time",getAfterWorkHour(start_time
            ,emt.getInt("end_inttime")*1.0/3600
            ,t_user.getExistfirst().getString("station_type")
            ,t_user.getExistfirst().getString("org_id")
            ));
            mapper.u_work(params);
        }
        
        return result;
    }
}